//
//  YXWorkSummarizeViewController.m
//  跑跑快销
//
//  Created by 杨潇 on 14-5-6.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "YXWorkSummarizeViewController.h"

@interface YXWorkSummarizeViewController ()

@end

@implementation YXWorkSummarizeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _workSummarizeVi = [[YXWorkSummarizeView alloc] init];
    self.view = _workSummarizeVi;
    _workSummarizeVi.textVi.delegate = self;
    
    UIBarButtonItem * commitBtn = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStyleBordered target:self action:@selector(touchCommitBtn)];
    self.navigationItem.rightBarButtonItem = commitBtn;
    
    for (int i = 0; i < 2; i ++) {
        UIButton * btn = (UIButton *)[_workSummarizeVi viewWithTag:i + 1];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
}

#pragma mark - ButtonsClick
- (void)touchCommitBtn
{
    
}

- (void)btnClick:(UIButton *)btn
{
    switch (btn.tag) {
        case 1:
        {
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                UIImagePickerController * cameraPick = [[UIImagePickerController alloc] init];
                cameraPick.sourceType = UIImagePickerControllerSourceTypeCamera;
                cameraPick.allowsEditing = YES;
                cameraPick.delegate = self;
                [self presentViewController:cameraPick animated:YES completion:nil];
            }else{
                [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:@"你的设备不支持相机功能。"];
            }
        }
            break;
        case 2:
        {
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
                UIImagePickerController * photoPicker = [[UIImagePickerController alloc] init];
                [photoPicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
                [photoPicker setDelegate:self];
                [photoPicker setAllowsEditing:YES];
                
                [self presentViewController:photoPicker animated:YES completion:nil];
            }else{
                [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:@"你的设备不支持相册功能。"];
            }
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - UITextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [self.view endEditing:YES];
        return NO;
    }
    return YES;
}

- (void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length == 0) {
        _workSummarizeVi.placeholderLab.hidden = NO;
    }else{
        _workSummarizeVi.placeholderLab.hidden = YES;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
